<div id="pinlei" style="overflow:hidden;">
<div class="topBar">
	<p style="padding:10px 5px 0px 10px;font-size:0.9em;margin:0px;">
		<span id="domain" onclick="javascript:showDistributerList();return false;">
			<?php 
				echo $this->title;
				echo '<input type="hidden" id="distributerId" value="'.$this->distributerId.'">';
			?>
		</span>
	</p>
	<div id="address" onclick="javascript:showDistributerList();return false;" style="color:#999;padding:0px 0px 5px 10px;font-size:0.8em;">
		<?php 
			echo $this->subTitle;
		?>
	</div>
</div>
<div class="clear"></div>

<?php
	$obj = $this->obj[0];
	$id = $obj->id;
	$logo = $obj->logo;
	$clientname = $obj->shopname;
	$contact = $obj->contact;
	
	echo '<div class="clear"></div>';
	echo '<input type="hidden" id="shopid" value="'.$id.'">';
	echo '<input type="hidden" id="custid" value="'.$obj->cust_id.'">';
	echo '<input type="hidden" id="etime" value="'.$obj->etime.'">';
	echo '<input type="hidden" id="stime" value="'.$obj->stime.'">';
?>



<input id="shopidIsNull" type="hidden" value="<?php echo $this->shopidIsNull;?>">
<div id="wrapper" class="Comman" style="top:60px;overflow:hidden;">
	<div class="sk_left scroller" style="overflow:hidden;">
		<ul>
			<?php 
			$start_tag = 0;
			$brand = $this->arr_brand;
			$bidArr = array();
			foreach($brand as $k=>$b){
				echo '
					<li class="leftli" onclick="javascript:brandHelper(this);return false;" brid="'.$k.'">'.$b.'</li>
				';
				array_push($bidArr,$k);
			}
			foreach($brand as $k=>$b){
				$start_tag = $k;
				break;
			}
			if(!empty($this->bid)&& !false == array_search($this->bid,$bidArr)){
				$start_tag = $this->bid;
			}
			?>
		</ul>
		<div style="height:80px;width:100%;">&nbsp;</div>
	</div>
</div>
<div class="clear"></div>


<div class="clear"></div>
	<div id="wrapperProduct" class="wrapper Comman"  style="float:left;width:76%;top:60px;overflow:hidden;">
	<div class="scroller" style="overflow:hidden;">
<?php 
	foreach($this->arr_productList as $k=>$re){
		echo '
		';
			foreach($re as $r){	
				echo '<div class="products" tag='.$k.'>';
				echo '
				<div id="pro-'.$r->skuid.'-0" skuName="'.$r->skuname.'" skuOnsale="'.$r->onsale.'" skuPrice="';
					if($r->onsale==0){
						echo $r->price;
					}if($r->onsale==1){
						echo $r->saleprice;
					}
				echo'" skuWeight="'.$r->spec.'" skuSaleAmount="'.$r->saleamount.'" skuImgUrl="'.$r->imgurl.'">
				<div class="sk_cai_left" sid="'.$r->id.'" onclick="javascript:skuDetails(this);return false;">';
				if($r->onsale==0){
					echo '<img src="'.$r->imgurl.'">';
				}if($r->onsale==1){
					echo '<div class="index_cujiao_div">
							
									<img style="width:100%;height:75%;" src="'.$r->imgurl.'"/>
									<img class="index_cujiao" style="width:20px;height:20px;" src="/images/cu.png"/>
							
						</div>';
				}	
				echo'</div>
				<div class="sk_cai_right">
					<input class="id" type="hidden" value="'.$r->skuid.'">
					<div class="sk_cai_name" sid="'.$r->id.'" onclick="javascript:skuDetails(this);return false;">'.$r->skuname.'</div>
					<div class="sk_num_left" sid="'.$r->id.'" onclick="javascript:skuDetails(this);return false;">
						<p class="sk_avg">'.$r->spec.'</p>';
						if($r->onsale==0){
							echo '<p class="sk_price">'.$r->price.'</p>';
						}if($r->onsale==1){
							echo '<p class="sk_price">'.$r->saleprice.'</p><p style="text-decoration:line-through;color:#919191;font-size:0.8em;">'.$r->price.'</p>';
						}
					echo '</div>
					<div class="sk_num_right">
						<div class="jiajian">
							<span class="minus"  skuId="'.$r->skuid.'" custId="0">  -  </span>
							<span class="text_box request-amount"  id="sku-'.$r->skuid.'-0">0</span>
							<span class="add"  skuId="'.$r->skuid.'" custId="0"> +  </span>
						</div>
					</div>
				</div>
				<div class="clear"></div>
				<hr class="hrcss">
				</div>
			</div>
			'; 
			}
	}
?>
	<div style="height:50px;">&nbsp;</div>
    </div>
	</div>
<input type="hidden" id="needAutoLocation" value="<?php echo $this->needAutoLocate;?>">
</div>
<?php 
if(!empty($this->distributerList)){
	echo'
	<div class="distributerCss" id="distributerList" style="display:none;">
		<p style="padding-top:10px;text-align:center;">'.$this->domain.'</p>
		<p style="text-align:center;border-bottom:1px solid #E6E6E6;">(请选择方便的自提点)</p>';
		
		foreach($this->distributerList as $n=>$d){
			echo '<div class="disList" id="disList'.$n.'" distributerId='.$d->id.' sitename='.str_replace(" ","",$d->sitename).' address='.str_replace(" ","",$d->address).' onclick="javascript:changeDistributer(this);return false;" style="padding:5px 10px;border-bottom:1px solid #E6E6E6;">
				<p style="float:left;width:80%;">'.$d->sitename.'</p>
				<p style="float:right;width:19%;text-align:center;font-size:0.8em;">距离</p>
				<div class="clear"></div>
				<p style="float:left;width:80%;font-size:0.9em;">'.$d->address.'</p>
				<p style="float:right;width:19%;text-align:center;color:red;">';
				if(substr($d->distance,0,4)>1){
					echo substr($d->distance,0,4);
				}else{
					echo substr($d->distance,0,4)*1000;
				}
				echo '<span style="font-size:0.8em;color:grey;">';
				if(substr($d->distance,0,4)>1){
					echo '公里';
				}else{
					echo '米';
				}
				echo'</span></p>
				<div class="clear"></div>
			</div>';
		}
	echo '
	</div>';
	echo '
		<script type="text/javascript">
			var hiddenDistuibuterId = $("#distributerId").val();
			if(isNull(hiddenDistuibuterId)){
				$("#disList0").css("color","green");
			}else{
				var len = $(".disList").length;
				for(var i=0;i<len;i++){
					var distributerId = $("#disList"+i).attr("distributerId");
					if(hiddenDistuibuterId == distributerId){
						$("#disList"+i).css("color","green");
					}
				}
			}
			$("body").append("<div id=\"masktg\"  onclick=\"javascript:hiddenFuCeng();return false;\"></div>");
			$("#masktg").addClass("mask").fadeOut("slow");
		</script>
	';
}
if(true == $this->needUpdateDistributer){
  echo '<script type="text/javascript">$("#distributerList").show();$("#masktg").show();</script>';
}
?>
<script type="text/javascript">
var myscrollProduct = '';
var myScrollBrid='';
$(document).ready(function() {
	$('.products').hide();
	$('.products[tag=<?php echo $start_tag?>]').show();
	$('.leftli[brid=<?php echo $start_tag?>]').addClass('left_li');
	
	var top = $('.topBar').css('height');
	$('.Comman').css('top',top);
	init_cart_btns();
	loadCookie(0);
	
	setTimeout(function () {
			myScrollBrid = new iScroll('wrapper');
			myscrollProduct = new iScroll('wrapperProduct', {momentum:false});
			clearCookie('brid');
			if(!isNull(getCookie('starty'))){
				myscrollProduct.scrollTo(0,parseInt(getCookie('starty')),100,false);
				clearCookie('starty');
			}
			if(!isNull(getCookie('starty_brid'))){
				myScrollBrid.scrollTo(0,parseInt(getCookie('starty_brid')),100,false);
				clearCookie('starty_brid');
			}
		}, 100);
});
//分类
function brandHelper(el){
	if($(el).hasClass('left_li')){
	}else{
			$('.sk_left li').removeClass('left_li');
			$('.sk_left li').removeClass('sk_left li');
			$(el).addClass('left_li');
			var bid = $(el).attr('brid');
			$('.products').hide();
			$('.products[tag='+bid+']').show();
		
			myscrollProduct.destroy();
			myscrollProduct = new iScroll('wrapperProduct', {momentum:false});
		
	}
}
function skuDetails(el){
	var id = $(el).attr('sid');
	var brid = $('.left_li').attr('brid');
	setCookie('brid',brid);
	var starty = myscrollProduct.startY;
	var startY_brid = myScrollBrid.startY;
	setCookie('starty',starty);
	setCookie('starty_brid',startY_brid);
	location.href='/sku/details?id='+id;
}
</script>